<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    // 定义全局组件
    /* 
    组件名 推荐 大驼峰
    或者 连接符 -
    */
    const CommonHead = {
      template:`
        <div>
          <h1>我是公共标题</h1>
          <h2>我是副标题</h2>  
          {{ msg }}
          {{ reverseMsg }}
          <button @click="changeMsg">
            改变msg  
          </button>

        </div>
      `,
      beforeCreate() {
        console.log('实例创建之前')
      },
      created() {
        console.log('实例创建完成')
      },
      beforeMount(){
        console.log('dom渲染之前')
      },
      mounted(){
        console.log('dom渲染完成');
      },
      beforeUpdate() {
        console.log('数据改变dom更新之前')
      },
      updated() {
        console.log('dom更新完毕')
      },
      beforeDestroy() {
        console.log('组件卸载之前')
      },
      destroyed() {
        console.log('组件已经卸载')
      },
      data(){
        return {
          msg: '你好组件'
        }
      },
      methods: {
        changeMsg(){
          this.msg = '数据改变了'
        }
      },
      watch: {
        msg(newVal){
          console.log('值改变了',newVal);
        }
      },
      computed: {
        reverseMsg(){
          return this.msg.split('').reverse().join('');
        }
      },
      mounted(){
        console.log(this);
      }
    }
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>